<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minSteps = function (n) {
      const f = new Array(n + 1).fill(0);
      for (let i = 2; i <= n; ++i) {
        f[i] = Number.MAX_SAFE_INTEGER;
        for (let j = 1; j * j <= i; ++j) {
          if (i % j === 0) {
            f[i] = Math.min(f[i], Math.floor(f[j] + i / j));
            f[i] = Math.min(f[i], Math.floor(f[i / j] + j));
          }
        }
      }
      return f[n];
    };
    console.log(minSteps(3));
  </script>
</body>

</html>